package com.example.demo.design.mode.singleton;

/**
 * @author liweizhi
 * @date 2020/4/15 00:00
 */
public enum SingletonTest001 {

    INSTANCE("大黄");
    private String name;

    SingletonTest001(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void say() {
        System.out.println("hello~");
    }

    public static void main(String[] args) {
        // 通过输出hashcode,可以判断其是否是多线程安全的单例
        for (int i = 0; i < 100; i++) {
            new Thread(() -> System.out.println(SingletonTest001.INSTANCE.hashCode())).start();
        }
    }
}
